<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/design/template.xhtml">
  <ui:define name="body">

  <h:form id="frmListSellers" prependId="false">
    <p:panel id="pnlListSellers" header="Fornecedores">

      <p:spacer height="10" />
      <p:messages for="frmListSellers"/>
      <p:dataTable id="tblSellers" value="#{sellerAction.sellers}" var="seller" style="width:100%;" columnsWidth="12%,35%,18%,20%,5%,10%" >
        <p:column style="text-align:center;">
          <f:facet name="header">
            <h:outputText value="Código" />
          </f:facet>
          <h:outputText value="#{seller.id}" style="#{!seller.activeStatus.active ? 'color: red;' : ''}" />
        </p:column>
        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Nome" />
          </f:facet>
          <h:outputText value="#{seller.name}" style="#{!seller.activeStatus.active ? 'color: red;' : ''}" />
        </p:column>
        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Tipo" />
          </f:facet>
          <h:outputText id="txtType" value="#{seller.type.name}" style="#{!seller.activeStatus.active ? 'color: red;' : ''}" />
        </p:column>
        <p:column style="text-align:left;">
          <f:facet name="header">
            <h:outputText value="Nome usuário web" />
          </f:facet>
          <h:outputText id="txtWebUserName" value="#{seller.webUserName}" style="#{!seller.activeStatus.active ? 'color: red;' : ''}" />
        </p:column>
        <p:column style="text-align:center;">
          <f:facet name="header">
            <h:outputText value="" />
          </f:facet>
          <h:graphicImage value="/images/ico_coments.gif" id="idComents" width="16" height="16" style="border: 0px;" title="#{seller.coments}" rendered="#{seller.hasComents}" />
        </p:column>

        <p:column style="text-align:center;">
          <h:commandLink id="lnkEdit" action="#{sellerAction.prepareEditSeller}" rendered="#{seller.activeStatus.active}">
            <h:graphicImage value="/images/action_edit.gif" id="idActionEdit" width="16" height="16" style="border: 0px;" title="editar fornecedor" />
            <f:setPropertyActionListener value="#{seller}" target="#{sellerAction.seller}" />            
          </h:commandLink>
          <p:spacer width="5" />
          <p:commandLink id="lnkDesactive" ajaxSingle="true" oncomplete="pnlConfirm.show()" rendered="#{seller.activeStatus.active}" update="pnlConfirm">
            <h:graphicImage value="/images/action_desabled.gif" id="idActionDesabled" width="16" height="16" style="border: 0px;" title="excluir fornecedor" />
            <f:setPropertyActionListener value="#{seller}" target="#{sellerAction.seller}" />            
            <f:setPropertyActionListener value="#{true}" target="#{sellerAction.actionDesactive}" />            
          </p:commandLink>
          <p:commandLink id="lnkActive" ajaxSingle="true" oncomplete="pnlConfirm.show()" rendered="#{!seller.activeStatus.active}" update="pnlConfirm">
            <h:graphicImage value="/images/action_enabled.gif" id="idActionEnabled" width="16" height="16" style="border: 0px;" title="recasdastrar fornecedor" />
            <f:setPropertyActionListener value="#{seller}" target="#{sellerAction.seller}" />            
            <f:setPropertyActionListener value="#{true}" target="#{sellerAction.actionActive}" />            
          </p:commandLink>
        </p:column>

      </p:dataTable>

      <p:spacer height="10" />
      <p:outputPanel id="pnlButons">
        <div align="right" id="divButons">
          <h:commandLink action="#{sellerAction.prepareInsertSeller}" value="incluir novo fornecedor" />
        </div>
      </p:outputPanel>			
      <p:spacer height="10" />
	  
      <p:dialog widgetVar="pnlConfirm" header="Confirmação" modal="true" resizable="false" draggable="false" width="250">
        <p:outputPanel id="pnlConfirm">  
        <table width="100%">
          <tbody>
            <tr>
              <td align="center" colspan="2" width="100%">
                <h:outputText value="Confirma #{sellerAction.actionActive ? 'recadastrar' : 'excluir'} o fornecedor #{sellerAction.seller.id}?" ></h:outputText>
              </td>
            </tr>
            <tr>
              <td align="center" colspan="2" width="100%" height="10"></td>
            </tr>
            <tr>
              <td align="center" width="50%">
                <p:commandButton value="confirmar" action="#{sellerAction.updateStatusSeller}" update="tblSellers" oncomplete="pnlConfirm.hide();" />
              </td>
              <td align="center" width="50%">
                <p:commandButton value="cancelar" onclick="pnlConfirm.hide();" />
              </td>
            </tr>
          </tbody>
        </table>
        </p:outputPanel>
      </p:dialog>
      
    </p:panel>
  </h:form>
    
  </ui:define>
</ui:composition>

